home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Classic
/
CD CLASSIC #1.iso
/
chess
/
eval.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-15
|
36KB
|
1,335 lines
/*
C source for GNU CHESS
Revision: 1990-09-30
Modified by Daryl Baker for use in MS WINDOWS environment
Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
Copyright (c) 1988, 1989, 1990 John Stanback
This file is part of CHESS.
CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY. No author or distributor accepts responsibility to anyone for
the consequences of using it or for whether it serves any particular
purpose or works at all, unless he says so in writing. Refer to the CHESS
General Public License for full details.
Everyone is granted permission to copy, modify and redistribute CHESS, but
only under the conditions described in the CHESS General Public License.
A copy of this license is supposed to have been given to you along with
CHESS so you can know your rights and responsibilities. It should be in a
file named COPYING. Among other things, the copyright notice and this
notice must be preserved on all copies.
*/
#define NOATOM
#define NOCLIPBOARD
#define NOCREATESTRUCT
#define NOFONT
#define NOREGION
#define NOSOUND
#define NOWH
#define NOWINOFFSETS
#define NOCOMM
#define NOKANJI
#include <windows.h>
#include <stdio.h>
#include "gnuchess.h"
#include "defs.h"
/*#define taxicab(a,b) taxidata[a][b]*/
#define taxicab(a,b) *(taxidata+a*64+b)
#define wking PieceList[white][0]
#define bking PieceList[black][0]
#define EnemyKing PieceList[c2][0]
/*extern short distdata[64][64], taxidata[64][64];*/
extern short far *distdata, far *taxidata;
/*extern unsigned char nextpos[8][64][64];*/
/*extern unsigned char nextdir[8][64][64];*/
extern unsigned char far * nextpos;
extern unsigned char far * nextdir;
extern short PieceList[2][16], PawnCnt[2][8];
extern short Pscore[maxdepth], Tscore[maxdepth];
extern short mtl[2], pmtl[2], emtl[2], hung[2];
extern short c1, c2, *atk1, *atk2, *PC1, *PC2, atak[2][64];
extern short ChkFlag[maxdepth], CptrFlag[maxdepth], PawnThreat[maxdepth];
extern short Pindex[64];
extern short PieceCnt[2];
extern short FROMsquare, TOsquare, Zscore, zwndw;
extern short Mking[2][64], Kfield[2][64];
extern short ATAKD, HUNGP, HUNGX, KCASTLD, KMOVD, XRAY, PINVAL;
extern short RHOPN, RHOPNX, KHOPN, KHOPNX, KSFTY;
extern short HasKnight[2], HasBishop[2], HasRook[2], HasQueen[2];
extern short Mwpawn[64], Mbpawn[64], Mknight[2][64], Mbishop[2][64];
extern short Mking[2][64], Kfield[2][64];
extern short KNIGHTPOST, KNIGHTSTRONG, BISHOPSTRONG, KATAK;
extern short PEDRNK2B, PWEAKH, PADVNCM, PADVNCI, PAWNSHIELD, PDOUBLED, PBLOK;
extern short stage, stage2, Developed[2];
extern short PawnBonus, BishopBonus, RookBonus;
static short _based(_segname("_CODE")) KingOpening[64] =
{0, 0, -4, -10, -10, -4, 0, 0,
-4, -4, -8, -12, -12, -8, -4, -4,
-12, -16, -20, -20, -20, -20, -16, -12,
-16, -20, -24, -24, -24, -24, -20, -16,
-16, -20, -24, -24, -24, -24, -20, -16,
-12, -16, -20, -20, -20, -20, -16, -12,
-4, -4, -8, -12, -12, -8, -4, -4,
0, 0, -4, -10, -10, -4, 0, 0};
static short _based(_segname("_CODE")) KingEnding[64] =
{0, 6, 12, 18, 18, 12, 6, 0,
6, 12, 18, 24, 24, 18, 12, 6,
12, 18, 24, 30, 30, 24, 18, 12,
18, 24, 30, 36, 36, 30, 24, 18,
18, 24, 30, 36, 36, 30, 24, 18,
12, 18, 24, 30, 30, 24, 18, 12,
6, 12, 18, 24, 24, 18, 12, 6,
0, 6, 12, 18, 18, 12, 6, 0};
static short _based(_segname("_CODE")) DyingKing[64] =
{0, 8, 16, 24, 24, 16, 8, 0,
8, 32, 40, 48, 48, 40, 32, 8,
16, 40, 56, 64, 64, 56, 40, 16,
24, 48, 64, 72, 72, 64, 48, 24,
24, 48, 64, 72, 72, 64, 48, 24,
16, 40, 56, 64, 64, 56, 40, 16,
8, 32, 40, 48, 48, 40, 32, 8,
0, 8, 16, 24, 24, 16, 8, 0};
static short _based(_segname("_CODE")) KBNK[64] =
{99, 90, 80, 70, 60, 50, 40, 40,
90, 80, 60, 50, 40, 30, 20, 40,
80, 60, 40, 30, 20, 10, 30, 50,
70, 50, 30, 10, 0, 20, 40, 60,
60, 40, 20, 0, 10, 30, 50, 70,
50, 30, 10, 20, 30, 40, 60, 80,
40, 20, 30, 40, 50, 60, 80, 90,
40, 40, 50, 60, 70, 80, 90, 99};
static short _based(_segname("_CODE")) pknight[64] =
{0, 4, 8, 10, 10, 8, 4, 0,
4, 8, 16, 20, 20, 16, 8, 4,
8, 16, 24, 28, 28, 24, 16, 8,
10, 20, 28, 32, 32, 28, 20, 10,
10, 20, 28, 32, 32, 28, 20, 10,
8, 16, 24, 28, 28, 24, 16, 8,
4, 8, 16, 20, 20, 16, 8, 4,
0, 4, 8, 10, 10, 8, 4, 0};
static short _based(_segname("_CODE")) pbishop[64] =
{14, 14, 14, 14, 14, 14, 14, 14,
14, 22, 18, 18, 18, 18, 22, 14,
14, 18, 22, 22, 22, 22, 18, 14,
14, 18, 22, 22, 22, 22, 18, 14,
14, 18, 22, 22, 22, 22, 18, 14,
14, 18, 22, 22, 22, 22, 18, 14,
14, 22, 18, 18, 18, 18, 22, 14,
14, 14, 14, 14, 14, 14, 14, 14};
static short _based(_segname("_CODE")) PawnAdvance[64] =
{0, 0, 0, 0, 0, 0, 0, 0,
4, 4, 4, 0, 0, 4, 4, 4,
6, 8, 2, 10, 10, 2, 8, 6,
6, 8, 12, 16, 16, 12, 8, 6,
8, 12, 16, 24, 24, 16, 12, 8,
12, 16, 24, 32, 32, 24, 16, 12,
12, 16, 24, 32, 32, 24, 16, 12,
0, 0, 0, 0, 0, 0, 0, 0};
static short _based(_segname("_CODE")) value[7] =
{0, valueP, valueN, valueB, valueR, valueQ, valueK};
static short _based(_segname("_CODE")) control[7] =
{0, ctlP, ctlN, ctlB, ctlR, ctlQ, ctlK};
static short _based(_segname("_CODE")) PassedPawn0[8] =
{0, 60, 80, 120, 200, 360, 600, 800};
static short _based(_segname("_CODE")) PassedPawn1[8] =
{0, 30, 40, 60, 100, 180, 300, 800};
static short _based(_segname("_CODE")) PassedPawn2[8] =
{0, 15, 25, 35, 50, 90, 140, 800};
static short _based(_segname("_CODE")) PassedPawn3[8] =
{0, 5, 10, 15, 20, 30, 140, 800};
static short _based(_segname("_CODE")) ISOLANI[8] =
{-12, -16, -20, -24, -24, -20, -16, -12};
static short _based(_segname("_CODE")) BACKWARD[16] =
{-6, -10, -15, -21, -28, -28, -28, -28,
-28, -28, -28, -28, -28, -28, -28, -28};
static short _based(_segname("_CODE")) BMBLTY[14] =
{-2, 0, 2, 4, 6, 8, 10, 12, 13, 14, 15, 16, 16, 16};
static short _based(_segname("_CODE")) RMBLTY[15] =
{0, 2, 4, 6, 8, 10, 11, 12, 13, 14, 14, 14, 14, 14, 14};
static short _based(_segname("_CODE")) KTHRT[36] =
{0, -8, -20, -36, -52, -68, -80, -80, -80, -80, -80, -80,
-80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80,
-80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80};
/*
ptype is used to separate white and black pawns, like this;
ptyp = ptype[side][piece]
piece can be used directly in nextpos/nextdir when generating moves
for pieces that are not black pawns.
*/
static short _based(_segname("_CODE")) ptype[2][8] =
{
no_piece, pawn, knight, bishop, rook, queen, king, no_piece,
no_piece, bpawn, knight, bishop, rook, queen, king, no_piece};
static short _based(_segname("_CODE")) direc[8][8] =
{
0, 0, 0, 0, 0, 0, 0, 0,
10, 9, 11, 0, 0, 0, 0, 0,
8, -8, 12, -12, 19, -19, 21, -21,
9, 11, -9, -11, 0, 0, 0, 0,
1, 10, -1, -10, 0, 0, 0, 0,
1, 10, -1, -10, 9, 11, -9, -11,
1, 10, -1, -10, 9, 11, -9, -11,
-10, -9, -11, 0, 0, 0, 0, 0};
static short _based(_segname("_CODE")) max_steps[8] =
{0, 2, 1, 7, 7, 7, 1, 2};
static short _based(_segname("_CODE")) nunmap[120] =
{
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, -1,
-1, 8, 9, 10, 11, 12, 13, 14, 15, -1,
-1, 16, 17, 18, 19, 20, 21, 22, 23, -1,
-1, 24, 25, 26, 27, 28, 29, 30, 31, -1,
-1, 32, 33, 34, 35, 36, 37, 38, 39, -1,
-1, 40, 41, 42, 43, 44, 45, 46, 47, -1,
-1, 48, 49, 50, 51, 52, 53, 54, 55, -1,
-1, 56, 57, 58, 59, 60, 61, 62, 63, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
static short _based(_segname("_CODE")) qrook[3] = {0, 56, 0};
static short _based(_segname("_CODE")) krook[3] = {7, 63, 0};
static short _based(_segname("_CODE")) kingP[3] = {4, 60, 0};
static short _based(_segname("_CODE")) rank7[3] = {6, 1, 0};
static short _based(_segname("_CODE")) sweep[8] =
{false, false, false, true, true, true, false, false};
/* ............ POSITIONAL EVALUATION ROUTINES ............ */
int
evaluate (short int side,
short int ply,
short int alph